package cn.ssh.action;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import cn.ssh.entity.SaleOrder;
import cn.ssh.entity.SaleOrderLine;
import cn.ssh.entity.SaleProduct;
import cn.ssh.service.OrderService;

import cn.ssh.service.SaleProductService;

public class OrderAction extends ActionSupport {
	private SaleOrder item;
	private OrderService orderService;
	private SaleProductService saleProductService;
	private SaleOrderLine line;

	public String toAdd() {
		return SUCCESS;
	}

	public String doAdd() {
		orderService.add(item);
		ActionContext ac = ActionContext.getContext();
		Map<String, Object> session = ac.getSession();
		session.put("id", item.getOdrId());
		return "addDetail";
	}

	public String toAddDetail() {
		ActionContext ac = ActionContext.getContext();
		Map<String, Object> session = ac.getSession();
		BigDecimal id = (BigDecimal) session.get("id");
		// SaleOrder order = orderService.get(id);
		this.item = orderService.getWithLines(id);
		List prodList = saleProductService.findAll();
		ac.put("prodList", prodList);
		return INPUT;
	}

	public String doAddDetail() {
		orderService.addDetail(line);
		ActionContext ac = ActionContext.getContext();
		Map<String, Object> session = ac.getSession();
		session.put("id", line.getSaleOrder().getOdrId());
		return "addDetail";
	}

	public SaleOrder getItem() {
		return item;
	}

	public void setItem(SaleOrder item) {
		this.item = item;
	}

	public OrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public SaleProductService getSaleProductService() {
		return saleProductService;
	}

	public void setSaleProductService(SaleProductService saleProductService) {
		this.saleProductService = saleProductService;
	}

	public SaleOrderLine getLine() {
		return line;
	}

	public void setLine(SaleOrderLine line) {
		this.line = line;
	}

}
